<?php
	session_start();
	include ("../includes/conn.php");
	
	if (!isset($_SESSION['id'])){
		$_SESSION['id'] = md5(rand());
	}
	
	//add product to shopping cart
	if (isset($addsign) && $addsign == '1'){
		require_once("../includes/cart.php");
	}
	
	//update shopping cart when amount and/or promo code change
	if (isset($button) && $button == 'Update'){
		if ($qtychg <> ''){
			require_once("../includes/cart-upd.php");
		}
	}
	
	// delete selected product in shopping cart
	if (isset($button2) && $button2 == 'Remove'){
		require_once ('../includes/cart-delete.php');
	}
	
	//empty all products in shopping cart
	if (isset($button5) && $button5 == 'Clear All' ){
		require_once ('../includes/cart-empty.php');
	}
	
	//check out shopping cart for payment
	if (isset($button3) && $button3 == 'Check Out' ){
		echo "<script language=javascript>location.href='/cart-checkout.php?';</script>";
		exit;
	}
	
	if (!isset($cart)){
		$cart = 0;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
<?php		if (isset($csn)){
			$pdsql="select * from category where sn='$csn'";
					$pdres=mysql_query($pdsql,$db);
					$pdrw=mysql_num_rows($pdres);
					if ($pdrw>0){
						$pdr=mysql_fetch_array($pdres);
						$catname = $pdr['cname'];
						$cname = "$catname |";
					}
			}else{$cname='';}
					
			if (isset($ssn)){
			$pdsql="select * from subcat where sn='$ssn'";
					$pdres=mysql_query($pdsql,$db);
					$pdrw=mysql_num_rows($pdres);
					if ($pdrw>0){
						$pdr=mysql_fetch_array($pdres);
						$subcatname = $pdr['sname'];
						$sname = "$subcatname | ";
					}
			}else{$sname='';}
			
			if (isset($dsn)){
				$pdsql="select * from chdcat where sn='$dsn'";
					$pdres=mysql_query($pdsql,$db);
					$pdrw=mysql_num_rows($pdres);
					if ($pdrw>0){
						$pdr=mysql_fetch_array($pdres);
						$chdcatname = $pdr['dname'];
						$dname = "$chdcatname | ";
					}
			}else{$dname='';}
			
			if (isset($catno)){
			$prd = "select * from prodothers where catNo like '$catno'";
			$prd_res = mysql_query($prd,$db);
			$prd_rows = mysql_num_rows($prd_res);
			if ($prd_rows > 0){
					$pdr = mysql_fetch_array($prd_res);
					$prodname = $pdr['pname'];
					$pname = "$prodname | ";
			}
			}else{$pname = '';}
			
			echo "$pname$dname$sname$cname ABM Inc.";
	?>
</title>
<link href="../style/abmnew.css" rel="stylesheet" type="text/css" />
<link href="../style/mirna.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#submenu {
	background:url(./images/marker.png) right top;
	background-repeat:no-repeat;
}
#prod-name {
	font-family:Arial, Helvetica, sans-serif;
	font-weight:bold;
	font-size:16px;
	color:#000;
	margin-top:-1px;
}
</style>
</head>
<body>
<?php include ("../includes/header.php");?>
<div id="content">
  <?php include ("../includes/logosearch.php");?>
  <div id='container'>
    <div id='leftmenu'>
      <?php include ("../includes/leftMenu.php");?>
    </div>
    <div id='rightcontent'>
      <div id='submenu'>
        <div id='subtitle'><?php echo"$catname";?></div>
      </div>
      <div id='title'>
        <?php 
				//get pathway
				$grp = "select * from category where sn = $csn";
				$grp_res = mysql_query($grp,$db);
				$grp_rows = mysql_num_rows ($grp_res);
				if ($grp_rows > 0){
					$grp_r = mysql_fetch_array($grp_res);
					$grpName = $grp_r['cname'];
					
					$sub = "select * from subcat where csn = $csn and sn = $ssn";
					$sub_res = mysql_query($sub,$db);
					$sub_rows = mysql_num_rows ($sub_res);
					if ($sub_rows > 0){
						$sub_r = mysql_fetch_array($sub_res);
						$subName = $sub_r['sname'];
					}
				}
				echo "$subcatname";
			?>
      </div>
      <div id='backbutton'> <?php echo "<span><a href='index.php?csn=$csn'>$grpName</a> &raquo; $subName</span>";?> <a href='index.php?csn=44&ssn=0'><img src="../../StemCell/images/arrow.png" width="5" height="10" border="0" /> Back</a> </div>
      <div id='prod-tab'>
        <ul>
          <?php
			//sets required variables if not set
			if (isset ($cart)){} else{$cart=0;}
            if (isset ($page)){} else{$page="data";}
			?>
          <?php
			//displays tabs in different forms based on 'page type' selected, they are in seperate php tags as otherwise no space appears between the tabs 
			if ($page=="data"){
					echo "<li><span class='tab-focus'>Data Sheet</span></li>";
			}else{echo "<li><a href='../expression/dispOne.php?page=data&cart=$cart&csn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno'>Data Sheet</a></li>";
			}?>
          <?php
            if ($protocol<>""){
            	if ($page=="protocol"){
					echo "<li><span class='tab-focus'>Protocol</span></li>";
				}else{ echo "<li><a href=''>Protocol</a></li>";
				}	
			}else{ echo "<li><span>Protocol</span></li>";
			}?>
          <?php
			if ($MSDS<>""){
            	if ($page=="MSDS"){
					echo "<li><span class='tab-focus'>MSDS</span></li>";
				}else{ echo "<li><a href=''>MSDS</a></li>";
				}
			}else{ echo "<li><span>MSDS</span></li>";
			}
			?>
          <li><span>FAQs</span></li>
          <li><span>Reviews</span></li>
          <?php 
				if (isset($_SESSION['usr']) && isset($_SESSION['admin'])){
					if ($_SESSION['admin']<>3){
						echo "
							<li><a href=''>Edit</a></li>
							<li><a href=''>Delete</a></li>
						";
					}
				}
			?>
        </ul>
      </div>
      <div id='prod-detail'>
        <div id='order'> &nbsp; To order products, check the corresponding boxes on the right and then click on add to cart.
          <form id="form2" name="form2" method="post" action="">
            <div id = 'exp-list'>
              <table id='exp-table' width='100%' border='0' cellspacing='0' cellpadding='0'>
                <tr>
                  <th height='22' align='left' width='22%'>Product</th>
                  <th align='left' width='39%'>Description</th>
                  <th align='center' width='16%'>Cat No.</th>
                  <th align='center' width='11%'>Price</th>
                  <th align='center' width='12%'><img src='../../img/icons/shopping_cart.png' width='17' height='17' /></th>
                </tr>
                <tr>
                  <td>Test</td>
                  <td align='left'>Test Description</td>
                  <td align='center'>ABC123</td>
                  <td align='center'>$999</td>
                  <td align='center'><input type='checkbox' name='grp[]' value='' /></td>
                </tr>
                <tr>
                  <td>Test</td>
                  <td align='left'>Test Description</td>
                  <td align='center'>ABC123</td>
                  <td align='center'>$999</td>
                  <td align='center'><input type='checkbox' name='grp[]' value='' /></td>
                </tr>
              </table>
            </div>
            <div id = 'exp-add'>
              <input name='car' type='hidden' id='car' value='1'/>
              <input type="hidden" name="addsign" id="addsign" value='1' />
              <input name='csn' type='hidden' id='csn' value='<?php echo $csn;?>'/>
              <input name='ssn' type='hidden' id='ssn' value='<?php echo $ssn;?>'/>
              <input name='dsn' type='hidden' id='dsn' value='<?php echo 0;?>'/>
              <input id="expcart" name="expcart" type="submit" value="Add to Cart" />
            </div>
          </form>
        </div>
        <div id='cart'><a href='?cart=<?php echo ($cart+1)%2;?>&amp;catno=<?php echo $catno;?>&amp;csn=<?php echo $csn;?>&amp;ssn=<?php echo $ssn;?>&amp;dsn=<?php echo $dsn;?>'><img id="carttab" src="../../images/cart.png" border="0" /></a></div>
        <div id='cart_detail'>
          <?php
            if ((isset($addmore) && $addmore == 'Add more') || (isset($bulkadd) && $bulkadd == 'Submit')){
                $ssid = $_SESSION['id'];
                for ($m=1;$m<11;$m++){
                    $cat = "cat".$m;
                    if ($$cat <> ''){
                        $catname = "cat".$m;
                        $quanname = "quan".$m;
                        $prmcdname = "prmcd".$m;
                        
                        $catval = $$catname;
                        $quanval = $$quanname;
                        $prmcdval = $$prmcdname;
						
						//check if there is a same product ordered under same ID
						$chk="select * from shoplist where sessionid='$ssid' and catNo='$catval' and promotioncode like '$prmcdval'";
						$chk_res=mysql_query($chk,$db);
						$chk_rw=mysql_num_rows($chk_res);
						if ($chk_rw>0){
							$upd="update shoplist set quantity = quantity + $quanval where sessionid='$ssid' and catNo='$catval' and promotioncode like '$prmcdval'";
							$ins_res=mysql_query($upd,$db);
						}else{
							$ins = "insert into shoplist (catNo,sessionid,quantity,promotioncode) values ('$catval','$ssid','$quanval','$prmcdval')";
							$ins_res = mysql_query($ins,$db);
						}
                        
                        if ($ins_res){ 
                            include ('../../includes/shoplist-upd.php');// update product name, dbNo, size and supplier info in shoplist table for each catNo
                        }
                    }
                }
            }
          ?>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <th width="17%" height="40">Cat. No.</th>
              <th width="37%">Product Name</th>
              <th width="6%">Qty.</th>
              <th width="14%" style="text-align:center;">Promo Code</th>
              <th width="11%" style="text-align:right;">Amount</th>
              <th width="7%"></th>
              <th width="8%"></th>
            </tr>
            <?php
				//shopping cart list
				$id=$_SESSION['id'];
				$crt="select * from shoplist where sessionid='$id'";
				$crtres=mysql_query($crt,$db);
				$crtrw=mysql_num_rows($crtres);
				if ($crtrw>0){
					$discnttotal = 0.00;
					$total=0.00;
					while ($cr=mysql_fetch_array($crtres)){
						$shpcatno = $cr['catNo'];
						$sn = $cr['sn'];
						$subtotal = $cr['price'] * $cr['quantity'];
						$pname = $cr['pname'];
						$quan = $cr['quantity'];
						$total += $subtotal;
						$promocode = $cr['promotioncode'];
						
						//search for discount by promocode
						$disc = "select * from promotion where promocode = '$promocode'";
						$disc_res = mysql_query($disc,$db);
						$disc_rows = mysql_num_rows($disc_res);
						if ( $disc_rows > 0 ){
							$disc_r = mysql_fetch_array($disc_res);
							$discnt = $disc_r['discountAmount'];
							$discnttotal += $discnt * $quan;
							$total = $total - $discnt * $quan;
						}
						echo "
          				<form id='form2' name='form2' method='post' action=''>
						  <tr>
							<td>$shpcatno</td>
							<td>$pname</td>
							<td style='text-align:center;'><input name='qtychg' type='text' id='qtychg' size='2' value='$quan' /></td>
							<td align='center'><input name='pmcode' type='text' id='pmcode' size='2' value='$promocode' /></td>
							<td><input name='subtotal' type='text' id='subtotal' size='5' value='$$subtotal' readonly='readonly' /></td>
							<td><input name='cart' type='hidden' value='1' />
								<input name='csn' type='hidden' id='csn' value='$csn'/>
								<input name='ssn' type='hidden' id='ssn' value='$ssn'/>
								<input name='dsn' type='hidden' id='dsn' value='$dsn'/>
								<input name='pcat' type='hidden' id='pcat' value='$csn'/>
								<input name='shpsn' type='hidden' id='shpsn' value='$sn'/>
								<input name='catno' type='hidden' id='catno' value='$catno'/>
								<input type='submit' name='button' id='button' value='Update' />
							</td>
							<td><input type='submit' name='button2' id='button2' value='Remove' /></td>
						  </tr>
						</form>";
					}
					echo"
					<form id='form3' name='form3' method='post' action=''>
					  <tr style='border-top:1px solid #E98F4E;'>
						<td height='24' colspan='2' style='border-top:1px solid #E98F4E;'>
							<input type='submit' name='button3' id='button3' value='Check Out' />
						  	<input type='submit' name='button4' id='button4' value='Quick Order' />
						</td>
						<td style='border-top:1px solid #E98F4E;'>&nbsp;</td>
						<td style='border-top:1px solid #E98F4E; color:#000; text-align:right; padding-right:5px;'>Discount:</td>
						<td style='border-top:1px solid #E98F4E;'><input name='subtotal' type='text' id='subtotal' size='5' value='- $$discnttotal' readonly='readonly' /></td>
						<td colspan='3' style='border-top:1px solid #E98F4E; text-align:right;'><input type='submit' name='button5' id='button5' value='Clear All' /></td>
					  </tr>
					</form>";
				}else{
					echo "
          			<form id='form3' name='form3' method='post' action=''>
					  <tr style='border-top:1px solid #E98F4E;'>
						<td height='24' colspan='2' style='border-top:1px solid #E98F4E;'>
						  <input type='submit' name='button4' id='button4' value='Quick Order' />
						</td>
						<td style='border-top:1px solid #E98F4E;'>&nbsp;</td>
						<td style='border-top:1px solid #E98F4E; color:#000; text-align:right; padding-right:5px;'>&nbsp;</td>
						<td style='border-top:1px solid #E98F4E;'>&nbsp;</td>
						<td colspan='3' style='border-top:1px solid #E98F4E; text-align:right;'>&nbsp;</td>
					  </tr>
					 </form>";
				}
              ?>
            <tr>
              <td colspan="2" height="10">&nbsp;</td>
              <td>&nbsp;</td>
              <td style="text-align:right; padding-right:5px;font-weight:bold;">Total: </td>
              <td><input name="total" type="text" id="total" size="5" value="<?php if (isset($total)){echo "$".$total;}else{echo "$0";}?>" readonly="readonly" /></td>
              <td colspan="2">&nbsp;</td>
            </tr>
          </table>
          <div id='quickadd'>
            <form id="form4" name="form4" method="post" action="">
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr style="font-weight:bold;">
                  <td width="41%" height="33" align="center">Catalog Number</td>
                  <td width="17%" align="center">Quantity</td>
                  <td width="42%" align="center">Promotion Code (Optional)</td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat1" id="cat1" /></td>
                  <td align="center"><input name="quan1" type="text" id="quan1" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd1" id="prmcd1" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat2" id="cat2" /></td>
                  <td align="center"><input name="quan2" type="text" id="quan2" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd2" id="prmcd2" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat3" id="cat3" /></td>
                  <td align="center"><input name="quan3" type="text" id="quan3" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd3" id="prmcd3" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat4" id="cat4" /></td>
                  <td align="center"><input name="quan4" type="text" id="quan4" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd4" id="prmcd4" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat5" id="cat5" /></td>
                  <td align="center"><input name="quan5" type="text" id="quan5" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd5" id="prmcd5" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat6" id="cat6" /></td>
                  <td align="center"><input name="quan6" type="text" id="quan6" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd6" id="prmcd6" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat7" id="cat7" /></td>
                  <td align="center"><input name="quan7" type="text" id="quan7" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd7" id="prmcd7" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat8" id="cat8" /></td>
                  <td align="center"><input name="quan8" type="text" id="quan8" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd8" id="prmcd8" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat9" id="cat9" /></td>
                  <td align="center"><input name="quan9" type="text" id="quan9" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd9" id="prmcd9" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat10" id="cat10" /></td>
                  <td align="center"><input name="quan10" type="text" id="quan10" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd10" id="prmcd10" /></td>
                </tr>
                <tr>
                  <td height="33" align="center">&nbsp;</td>
                  <td align="center">&nbsp;</td>
                  <td align="center"><input type="submit" name="addmore" id="addmore" value="Add more" />
                    <input type="submit" name="bulkadd" id="bulkadd" value="Submit" /></td>
                </tr>
              </table>
            </form>
          </div>
        </div>
        <?php
			if (($cart)%2 == 0){
				echo "<script language=javascript>document.getElementById('cart_detail').style.display='none';</script>";
			}else{
				echo "<script language=javascript>document.getElementById('cart_detail').style.display='block'; document.getElementById('carttab').src='../../images/cart-up.png';</script>";
			}
			
			if (isset($button4) && $button4 == 'Quick Order' ){
				echo "<script language=javascript>document.getElementById('quickadd').style.display='block'; </script>";
			}
			
			if (isset($bulkadd)){
				echo "<script language=javascript>document.getElementById('quickadd').style.display = 'none';</script>";
			}
			
			if (isset($addmore)){
				echo "<script language=javascript>document.getElementById('quickadd').style.display = 'block';</script>";
			}
		?>
        <?php
			  //displays data sheet information for ALL product types
			  switch ($page){
				case "data":
					echo"
					<div id='tab-title'>Data Sheet</div>
						<div id='tab-detail'>
							<div id='panswer'><a href=''>Print Version</a></div>
							<div id='question'>TEST QUESTION1</div>
							<div id='answer'>TEST ANSWER1</div>
							<div id='question'>TEST QUESTION2</div>
							<div id='answer'>TEST ANSWER2</div>
						</div>
					</div>";
				    break;
					//displays MSDS information for virus products
					case "MSDS":
						echo "
						<div id='tab-title'>MSDS</div>
							<div id='MSDS'>";
							include ("../includes/UTRChemMSDS.php");
						echo "
							</div>
						</div>
						";
					 break;
					//displays protocol information for adeno products 
					case "protocol":
						echo "
						<div id='tab-title'>Protocol</div>
							<div id='MSDS'>";
							include ("../includes/$protocol.php");
						echo "
							</div>
						</div>
						";
					 break;
				  }
			 ?>
      </div>
    </div>
  </div>
</div>
<div id='foot'>
  <p><a href="../../TechSupport/support.php" class="mnu1">Technical Support</a>&nbsp; | &nbsp;<a href="../../RelatedLiter/related.php" class="mnu1">Related Literature</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&copy; <?php echo date("Y");?> Applied Biological Materials Inc. </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>

<!-- Piwik --> 
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.abmgood.com/piwik/" : "http://www.abmgood.com/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script>
<noscript>
<p><img src="http://www.abmgood.com/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p>
</noscript>
<!-- End Piwik Tag -->
</body>
</html>